package com.hoshiicloud.payment.controller;

import com.hoshiicloud.payment.service.CallBackService;
import com.hoshiicloud.payment.util.TensoonUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.io.IOUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

//TODO 添加退款回调
@Api(value = "第三方支付回调", tags = "第三方支付回调")
@Slf4j
@Controller
@RequestMapping("/callBack")
public class CallBackController {
    @Autowired
    private CallBackService callBackService;

    @ApiOperation(value = "微信支付回调")
    /**
     *
     * @param request
     * @param response
     * @Author: Mr.wu
     * @Descripton:
     * @Date: 10:19 2019/5/16
     */
    @PostMapping("/wxPay")
    public void wxPayCallBack(HttpServletRequest request, HttpServletResponse response) {
        log.info("微信支付回调开始---------------");
        try {
            String str = IOUtils.toString(request.getInputStream(), "UTF-8");
            TensoonUtil.responseWriteString(response, callBackService.wxPayCallBack(str));
        } catch (Exception e) {
            log.error("微信支付回调异常：", e);
        }

    }

    @PostMapping("/wxRefund")
    public void wxRefundCallBack(HttpServletRequest request, HttpServletResponse response) {
        log.info("微信退款回调开始---------------");
        try {
            String str = IOUtils.toString(request.getInputStream(), "UTF-8");
            TensoonUtil.responseWriteString(response, callBackService.wxRefundCallBack(str));
        } catch (Exception e) {
            log.error("微信退款回调异常：", e);
        }
    }

    @ApiOperation(value = "支付宝支付回调")
    public void alipayCallBack() {

    }


}
